package com.gpc.hexapods.data;


import com.gpc.hexapods.utils.MathUtil;

public class Leg1Data {

    public static final float LENGTH = 0.2f;
    public static final float WIDTH = 0.12f;
    public static final float HEIGHT = 0.2f;

    public Point point;
    public float angle;

    public float[] position;
    public short[] index;
    public float[] color;

    public Leg1Data(Point point, float angle) {
        this.point = point;
        this.angle = angle;
        this.position = getPosition(point, angle);
        initData();
    }

    public float[] getPosition(Point point, float angle) {
        return new float[]{
                //正面左上0
                point.x - LENGTH * MathUtil.sin(angle) - WIDTH * MathUtil.cos(angle),
                point.y + LENGTH * MathUtil.cos(angle) - WIDTH * MathUtil.sin(angle),
                HEIGHT,

                //正面左下1
                point.x + LENGTH * MathUtil.sin(angle) - WIDTH * MathUtil.cos(angle),
                point.y - LENGTH * MathUtil.cos(angle) - WIDTH * MathUtil.sin(angle),
                HEIGHT,

                //正面右下2
                point.x + LENGTH * MathUtil.sin(angle) + WIDTH * MathUtil.cos(angle),
                point.y - LENGTH * MathUtil.cos(angle) + WIDTH * MathUtil.sin(angle),
                HEIGHT,

                //正面右上3
                point.x - LENGTH * MathUtil.sin(angle) + WIDTH * MathUtil.cos(angle),
                point.y + LENGTH * MathUtil.cos(angle) + WIDTH * MathUtil.sin(angle),
                HEIGHT,

                //反面左上4
                point.x - LENGTH * MathUtil.sin(angle) - WIDTH * MathUtil.cos(angle),
                point.y + LENGTH * MathUtil.cos(angle) - WIDTH * MathUtil.sin(angle),
                -HEIGHT,

                //反面左下5
                point.x + LENGTH * MathUtil.sin(angle) - WIDTH * MathUtil.cos(angle),
                point.y - LENGTH * MathUtil.cos(angle) - WIDTH * MathUtil.sin(angle),
                -HEIGHT,

                //反面右下6
                point.x + LENGTH * MathUtil.sin(angle) + WIDTH * MathUtil.cos(angle),
                point.y - LENGTH * MathUtil.cos(angle) + WIDTH * MathUtil.sin(angle),
                -HEIGHT,

                //反面右上7
                point.x - LENGTH * MathUtil.sin(angle) + WIDTH * MathUtil.cos(angle),
                point.y + LENGTH * MathUtil.cos(angle) + WIDTH * MathUtil.sin(angle),
                -HEIGHT,
        };
    }

    public void initData() {
        index = new short[]{
                0, 3, 2, 0, 2, 1,    //正面
                0, 1, 5, 0, 5, 4,    //左面
                0, 7, 3, 0, 4, 7,    //上面
                6, 7, 4, 6, 4, 5,    //后面
                6, 3, 7, 6, 2, 3,    //右面
                6, 5, 1, 6, 1, 2     //下面
        };

        color = new float[]{
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,

                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,

                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,

                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
        };
    }
}
